<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="直播标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入直播标题"
          clearable
        />
      </el-form-item>
      <el-form-item label="会员名称" prop="memberName">
        <el-input
          v-model="queryParams.memberName"
          placeholder="请输入会员名称"
          clearable
        />
      </el-form-item>
      <!-- <el-form-item label="直播链接" prop="broadUrl">
        <el-input
          v-model="queryParams.broadUrl"
          placeholder="请输入主播链接"
          clearable
        />
      </el-form-item>
      <el-form-item label="预约会员" prop="advReservbroadcastId">
        <el-input
          v-model="queryParams.advReservbroadcastId"
          placeholder="请输入预约会员"
          clearable
        />
      </el-form-item>
      <el-form-item label="直播开始时间" prop="begintime">
        <el-date-picker
          v-model="queryParams.begintime"
          type="date"
          placeholder="请选择直播开始时间"
          style="width: 180px"
        />
      </el-form-item>
      <el-form-item label="直播开始时间" prop="endtime">
        <el-date-picker
          v-model="queryParams.endtime"
          type="date"
          placeholder="请选择直播结束时间"
          style="width: 180px"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <!-- <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:role:add']"
        >新增</el-button> -->
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:role:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete2"
          v-hasPermi="['system:role:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:role:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="直播标题" align="center" prop="title" />
      <el-table-column label="直播内容" align="center" prop="content" />
      <el-table-column label="直播链接" align="center" prop="broadUrl" />
      <el-table-column label="预约会员" align="center" prop="memberName" />
      <el-table-column label="直播开始时间" align="center" prop="begintime" />
      <el-table-column label="直播结束时间" align="center" prop="endtime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:role:edit']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:role:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
    v-show="total>0"
    :total="total"
    :page.sync="queryParams.pageNum"
    :limit.sync="queryParams.pageSize"
    @pagination="getList"
  />

    <!-- 添加或修改用户和角色关联对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="直播标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入主播标题" clearable disabled/>
        </el-form-item>
        <el-form-item label="直播内容" prop="content">
          <el-input v-model="form.content" placeholder="请输入主播内容" clearable disabled/>
        </el-form-item>
        <el-form-item label="直播链接" prop="broadUrl">
          <el-input v-model="form.broadUrl" placeholder="请输入主播链接" clearable disabled/>
        </el-form-item>
        <el-form-item label="预约会员" prop="memberName">
          <el-input v-model="form.memberName" placeholder="请输入预约会员" clearable disabled/>
        </el-form-item>
        <el-form-item label="直播开始时间" prop="begintime" >
          <el-date-picker
            v-model="form.begintime"
            type="date"
            placeholder="请选择直播开始时间"
            style="width: 180px"
            disabled
          />
        </el-form-item>
        <el-form-item label="直播结束时间" prop="endtime" >
          <el-date-picker
            v-model="form.endtime"
            type="date"
            placeholder="请选择直播结束时间"
            style="width: 180px"
            disabled
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listReservbroadcast, getReservbroadcast, addReservbroadcast, updateReservbroadcast, delReservbroadcast } from '@/api/server/reservbroadcast.js'
export default {
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nickname: "",
        username: "",
        parentUsername: "",
        status: "",
        isAnchor: ""
      },
      showSearch: true,
      single: false,
      multiple: false,
      loading: false,
      currentPage4: 1,
      roleList: [
       
      ],
      total: 0,
      title: "",
      open: false,
      form: {},
      rules: {
        nickname: [
          { required: true, message: "请输入主播标题", trigger: "blur" }
        ],
        username: [
          { required: true, message: "请输入主播内容", trigger: "blur" }
        ],
        parentUsername: [
          { required: true, message: "请输入主播链接", trigger: "blur" }
        ],
        appointmentUser: [
          { required: true, message: "请输入预约会员", trigger: "blur" }
        ],
        startTime: [          
          { required: true, message: "请选择直播开始时间", trigger: "change" }
        ],
        endTime: [
          { required: true, message: "请选择直播结束时间", trigger: "change" }
        ],
        status: [
          { required: true, message: "请选择主播状态", trigger: "change" }
        ],
        isAnchor: [
          { required: true, message: "请选择是否主播", trigger: "change" }
        ],
      },
    }
  },
  created() {
    this.getList();
  },
  methods: {
    handleDelete2(){
      this.$confirm('此操作将永久删除该直播, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delReservbroadcast(this.ids.join(',')).then((response) => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.getList();
        }).catch((error) => {
          this.$message({
            type: 'error',
            message: '删除失败!'
          });
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    handleQuery() {
      this.getList();
    },
    resetQuery() {},
    handleExport() {
      this.download('/system/reservbroadcast/export', {
        ...this.queryParams
      }, `直播预约清单_${new Date().getTime()}.xlsx`)
    },
    getList() {
      listReservbroadcast(this.queryParams).then((response) => {
        console.log(response.rows)
        this.roleList = response.rows;
        this.total = response.total;
      })
    },
    handleSelectionChange() {},
    cancel() {
      this.open = false;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.advReservbroadcastId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加预约信息";
    },
    handleUpdate(row) {
      this.reset();
      this.form = row;
      this.open = true;
      this.title = "修改预约信息";
    },
    reset() {
      this.form = {
        nickname: "",
        username: "",
        parentUsername: "",
        status: "",
        isAnchor: ""
      }
    },
    handleDelete(row) {
      this.$confirm('此操作将永久删除该预约 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delReservbroadcast(row.advReservbroadcastId).then((response) => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.getList()
        })
        
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    submitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$message({
            type: 'success',
            message: '提交成功!'
          });
          this.open = false;
        } else {
          this.$message({
            type: 'error',
            message: '表单验证失败!'
          });
        }
      })
    },
    handleSolid(row) {
      this.$confirm('此操作将永久拉黑该主播, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '拉黑成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消拉黑'
        });
      });
    },
    handleStop(row) {
      this.$confirm('此操作将永久禁用该主播, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '禁用成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消禁用'
        });
      });
    },
    
  }
}
</script>

<style>

</style>

